﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;

namespace FDeal.WUC
{
    public partial class WUC_DN_HieuChinh : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] == null)
                    Response.Redirect("~/PH_DoanhNghiep/PHDN_Default.aspx");
                else
                {
                    LoadThongTin();
                }
            }
        }

        protected void btn_Update_Click(object sender, EventArgs e)
        {
            // get thong tin
            CHITIETDEAL tChiTietDeal = new CHITIETDEAL();

            tChiTietDeal.TIEUDE = txt_TieuDe.Text.Trim();
            tChiTietDeal.LOAIDEAL = "";
            tChiTietDeal.TOMTATDEAL = txt_TomTat.Text.Trim();
            tChiTietDeal.GIAGOC = float.Parse(txt_GiaGoc.Text);
            tChiTietDeal.DONVI = ddl_DonViTinh.SelectedValue;
            tChiTietDeal.GIAM = int.Parse(txt_Giam.Text);
            tChiTietDeal.GIACONLAI = tChiTietDeal.GIAGOC - tChiTietDeal.GIAM;
            tChiTietDeal.SODEALBAN = int.Parse(txt_SoLuong.Text);
            tChiTietDeal.THOIGIANCONLAI = int.Parse(txt_ThoiGian.Text);
            tChiTietDeal.HINHANH = "";
            tChiTietDeal.DIEUKIEN = txt_DieuKien.Text.Trim();
            tChiTietDeal.DIEMNOIBAT = txt_DiemNoiBat.Text.Trim();
            tChiTietDeal.DIACHI = txt_DiaChi.Text.Trim();
            tChiTietDeal.DIADIEMBANDEAL = txt_DiaDiemBan.Text.Trim();
            tChiTietDeal.NGUOIDANG = txt_NguoiDang.Text.Trim();

            tChiTietDeal.SONGUOIMUA = 0;
            tChiTietDeal.LUOTXEM = 0;
            tChiTietDeal.NGAYDANG = DateTime.Now;

            // sua thong tin

            new BUS.ChiTietDealBUS().Sua(tChiTietDeal);
        }

        public void LoadThongTin()
        {
            ddl_LoaiDeal.DataSource = new BUS.LoaiDealBUS().LietKe();
            ddl_LoaiDeal.DataBind();

            string idDN = Request.QueryString["id"].ToString();

            BUS.ChiTietDealBUS dhbus = new BUS.ChiTietDealBUS();
            DAO.CHITIETDEAL tChiTietDeal = dhbus.ChiTiet(idDN);

            txt_TieuDe.Text = tChiTietDeal.TIEUDE;
            ddl_LoaiDeal.Text = tChiTietDeal.LOAIDEAL;
            txt_TomTat.Text = tChiTietDeal.TOMTATDEAL;
            txt_GiaGoc.Text = tChiTietDeal.GIAGOC.ToString();
            ddl_DonViTinh.SelectedValue = tChiTietDeal.DONVI;
            txt_Giam.Text = tChiTietDeal.GIAM.ToString();
            txt_SoLuong.Text = tChiTietDeal.SODEALBAN.ToString();
            txt_ThoiGian.Text = tChiTietDeal.THOIGIANCONLAI.ToString();
            //  = tChiTietDeal.HINHANH = "";
            txt_DieuKien.Text = tChiTietDeal.DIEUKIEN;
            txt_DiemNoiBat.Text = tChiTietDeal.DIEMNOIBAT;
            txt_DiaChi.Text = tChiTietDeal.DIACHI;
            txt_DiaDiemBan.Text = tChiTietDeal.DIADIEMBANDEAL;
            txt_NguoiDang.Text = tChiTietDeal.NGUOIDANG;
        }
    }
}